<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>系统管理-部门</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="${s.base}/js/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="${s.base}/css/base/base.css" media="all" /></head>

<body class="childrenBody">
<form class="layui-form">
	<blockquote class="layui-elem-quote quoteBox" id="tool">
		<div class="layui-inline">
			<label class="layui-input-inline">名称</label>
			<label class="layui-input-inline">
				<input type="text" class="layui-input" name="name" placeholder="请输入名称" /></label>
			<a class="layui-btn search_btn" lay-submit="" lay-filter="seacherTreeBtn">搜索</a></div>
		<div class="layui-inline">
			<a class="layui-btn layui-btn-normal addBtn" data-title="添加" data-url="/sysDepart/getEntity">添加</a></div>
	</blockquote>
	<table id="entityList" lay-filter="entityList"></table>
</form>
<script type="text/javascript" src="${s.base}/js/layui/layui.js"></script>
<script type="text/javascript" src="${s.base}/js/base/base.js"></script>
<script type="text/javascript">
    layui.use(['jquery','pageUtil','form'], function(){
        var $=layui.jquery,
            form = layui.form,
            pageUtil = layui.pageUtil;
        var treeGridTable=null;
        pageUtil.initDict("sys_menu_grade", function (dictData) {
            var url="/sysDepart/list";
            var cols=[
                {type:'numbers',
                    width: '10%'},
                {
                    field: 'name',
                    title: '部门名称',
                    width: '30%'
                },{
                    field: 'grade',
                    title: '级别', templet:function(d){
                        return pageUtil.aceeptDictContentName(dictData,"sys_menu_grade",d.grade);
                    },
                    align:'center',
                    width: '20%'
                },{
                    field: 'sort',
                    title: '排序',
                    align:'center',
                    width: '10%'
                },{
                    field: 'code',
                    title: '部门code',
                    width: '10%'
                },
                {width:'20%', fixed: 'right',title: '操作', align:'left',templet:function(d){
                    return '<a class="layui-btn cy-btnbg-edit layui-btn-sm" lay-event="add">添加</a>'+
                        '<a class="layui-btn cy-btnbg-edit layui-btn-sm" lay-event="edit">编辑</a>'+
                        '<a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</a>';
                }}
            ];
            treeGridTable = pageUtil.initTreeGridDate(cols,url,true,'parentId','name');
        });
        pageUtil.initTreeGridOn(function (obj) {
            if(obj.event === 'del'){//删除行
                pageUtil.delete("确定删除【"+obj.data.name+"】部门吗？","/sysDepart/delete", {"id":obj.data.id,"_method":"DELETE"},function (data) {
                    pageUtil.initTreeGridQuery("");
                });
            }else if(obj.event==="add"){//添加行
                pageUtil.editPopup("添加","/sysDepart/getEntity?parentId="+obj.data.id);
            }else if(obj.event==="edit"){//编辑行
                pageUtil.editPopup("编辑","/sysDepart/getEntity?id="+obj.data.id+"&parentId="+obj.data.parentId);
            }
        })
        /**
         * 工具栏-搜索
         */
        form.on('submit(seacherTreeBtn)', function (data) {
            pageUtil.initTreeGridQuery(data.field);
            return false;
        });

    });

</script>
</body>

</html>